//
//  MBStatisticsTableViewCell.m
//  MemberBusiness-ios
//
//  Created by cherry pu on 2018/4/24.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBStatisticsTableViewCell.h"

@interface MBStatisticsTableViewCell ()
@property (nonatomic,weak)UIImageView* numImageView;
@property (nonatomic,weak)UILabel* numLabel;
@property (nonatomic,weak)UILabel* nameLabel;
@property (nonatomic,weak)UILabel* saleNumLabel;
@property (nonatomic,weak)UILabel* moneyLabel;


@end

@implementation MBStatisticsTableViewCell
@dynamic viewModel;

-(void)setupLayout
{
    [super setupLayout];
    
    UIImageView* numImageView = [[UIImageView alloc]init];
    self.numImageView = numImageView;
    numImageView.image = [UIImage imageNamed:@"statistics_1"];
    [self.contentView addSubview:numImageView];
    
    [numImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset([UIView lf_sizeFromIphone6:22]);
    }];
    
    UILabel* numLabel = [[UILabel alloc]init];
    self.numLabel = numLabel;
    numLabel.hidden = YES;
    numLabel.text = @"4";
    numLabel.font = [UIFont lf_systemFontOfSize:13];
    numLabel.textColor = [UIColor colorWithR:24 G:24 B:24];
    [self.contentView addSubview:numLabel];
    
    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(numImageView);
    }];

    UILabel* nameLabel = [[UILabel alloc]init];
    self.nameLabel = nameLabel;
    nameLabel.text = @"荣耀7 双卡双待通移动4G 16G存储（…";
    nameLabel.font = [UIFont lf_systemFontOfSize:12];
    nameLabel.textColor = [UIColor colorWithR:24 G:24 B:24];
    nameLabel.numberOfLines = 0;
    [self.contentView addSubview:nameLabel];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset([UIView lf_sizeFromIphone6:76]);
        make.width.mas_equalTo([UIView lf_sizeFromIphone6:107]);
    }];

    UILabel* saleNumLabel = [[UILabel alloc]init];
    self.saleNumLabel = saleNumLabel;
    saleNumLabel.text = @"1745";
    saleNumLabel.font = [UIFont lf_systemFontOfSize:13];
    saleNumLabel.textColor = [UIColor colorWithR:24 G:24 B:24];
    [self.contentView addSubview:saleNumLabel];
    
    [saleNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self).offset([UIView lf_sizeFromIphone6:238]);
    }];

    UILabel* moneyLabel = [[UILabel alloc]init];
    self.moneyLabel = moneyLabel;
    moneyLabel.text = @"284562.00";
    moneyLabel.font = [UIFont lf_systemFontOfSize:13];
    moneyLabel.textColor = [UIColor colorWithR:24 G:24 B:24];
    [self.contentView addSubview:moneyLabel];
    
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-[UIView lf_sizeFromIphone6:20]);
    }];
}

-(void)setupData
{
    [super setupData];
    
    self.nameLabel.text = self.viewModel.dataModel.goods_name;
    self.moneyLabel.text = self.viewModel.dataModel.sale_amount;
    self.saleNumLabel.text = self.viewModel.dataModel.sale_num;
    if (self.viewModel.dataModel.num < 4) {
        self.numImageView.hidden = NO;
        self.numLabel.hidden = YES;
        self.numImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"statistics_%d",self.viewModel.dataModel.num]];
    }else {
        self.numImageView.hidden = YES;
        self.numLabel.hidden = NO;
        self.numLabel.text = [NSString stringWithFormat:@"%d",self.viewModel.dataModel.num];
    }
}

// 用来计算高度
+(NSNumber*)calculateRowHeightWithViewModel:(MBStatisticsTableCellViewModel *)viewModel
{
    return [viewModel cacheCellHeightWithCalculateBlock:^NSNumber * _Nonnull{
        return viewModel.totalHeight;
    }];
}


@end
